from playwright.sync_api import Page


class Music163Page:
    """
    网易云音乐页面
    """
    # 登录-按钮
    _loginBTN = "[data-action='login']"
    # 选择其他登录方式
    _otherLoginMode = "a._3xIXD0Q6"
    # 同意-官方条款
    _officialTerms = "#j-official-terms"
    # 手机号登录/注册
    _phoneLogin = ".tan2MIhq"
    # 密码登录
    _passwordLogin = "div._3Mb1fXSG>a"
    # 手机号
    _phoneNum = "input._2OT0mQUQ"
    # 密码
    _password = "input.sR89MU1J"
    # 登录
    _loginBtn = "div.tan2MIhq"
    """
    页面方法层
    """

    def __init__(self, page: Page):
        self.page = page

    def login(self, username, password):
        """
        登录
        """
        self.page.goto('https://music.163.com')
        self.page.wait_for_load_state()
        self.page.locator(self._loginBTN).click()
        self.page.locator(self._otherLoginMode).click()
        self.page.locator(self._officialTerms).check()
        self.page.locator(self._phoneLogin).click()
        self.page.locator(self._passwordLogin).click()
        # 录入账号、密码
        self.page.locator(self._phoneNum).fill(username)
        self.page.locator(self._password).fill(password)
        self.page.locator(self._loginBtn).click()
        self.page.wait_for_timeout(5000)
